// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso;

import java.awt.Dimension;
import java.awt.Point;

public final class Vector3 implements Cloneable {
    public float x;
    public float y;
    public float z;

    public Vector3() {
        this.x = 0.0F;
        this.y = 0.0F;
        this.z = 0.0F;
    }

    public Vector3(Vector3 other) {
        this.x = other.x;
        this.y = other.y;
        this.z = other.z;
    }

    public Vector3(float _x, float _y, float _z) {
        this.x = _x;
        this.y = _y;
        this.z = _z;
    }

    public static Vector2 fromAwtPoint(Point p) {
        return new Vector2((float)p.x, (float)p.y);
    }

    public static Vector2 fromLengthDirection(float length, float direction) {
        Vector2 vector2 = new Vector2();
        vector2.setLengthAndDirection(direction, length);
        return vector2;
    }

    public static float dot(float _x, float _y, float tx, float ty) {
        return _x * tx + _y * ty;
    }

    public void rotate(float rad) {
        double double0 = (double)this.x * Math.cos((double)rad) - (double)this.y * Math.sin((double)rad);
        double double1 = (double)this.x * Math.sin((double)rad) + (double)this.y * Math.cos((double)rad);
        this.x = (float)double0;
        this.y = (float)double1;
    }

    public void rotatey(float rad) {
        double double0 = (double)this.x * Math.cos((double)rad) - (double)this.z * Math.sin((double)rad);
        double double1 = (double)this.x * Math.sin((double)rad) + (double)this.z * Math.cos((double)rad);
        this.x = (float)double0;
        this.z = (float)double1;
    }

    public Vector2 add(Vector2 other) {
        return new Vector2(this.x + other.x, this.y + other.y);
    }

    public Vector3 addToThis(Vector2 other) {
        this.x = this.x + other.x;
        this.y = this.y + other.y;
        return this;
    }

    public Vector3 addToThis(Vector3 other) {
        this.x = this.x + other.x;
        this.y = this.y + other.y;
        this.z = this.z + other.z;
        return this;
    }

    public Vector3 div(float scalar) {
        this.x /= scalar;
        this.y /= scalar;
        this.z /= scalar;
        return this;
    }

    public Vector3 aimAt(Vector2 other) {
        this.setLengthAndDirection(this.angleTo(other), this.getLength());
        return this;
    }

    public float angleTo(Vector2 other) {
        return (float)Math.atan2((double)(other.y - this.y), (double)(other.x - this.x));
    }

    public Vector3 clone() {
        return new Vector3(this);
    }

    public float distanceTo(Vector2 other) {
        return (float)Math.sqrt(Math.pow((double)(other.x - this.x), 2.0) + Math.pow((double)(other.y - this.y), 2.0));
    }

    public float dot(Vector2 other) {
        return this.x * other.x + this.y * other.y;
    }

    public float dot3d(Vector3 other) {
        return this.x * other.x + this.y * other.y + this.z * other.z;
    }

    public boolean equals(Object other) {
        return !(other instanceof Vector2 vector2) ? false : vector2.x == this.x && vector2.y == this.y;
    }

    public float getDirection() {
        return (float)Math.atan2((double)this.x, (double)this.y);
    }

    public Vector3 setDirection(float direction) {
        this.setLengthAndDirection(direction, this.getLength());
        return this;
    }

    public float getLength() {
        float _float = this.getLengthSq();
        return (float)Math.sqrt((double)_float);
    }

    public float getLengthSq() {
        return this.x * this.x + this.y * this.y + this.z * this.z;
    }

    public Vector3 setLength(float length) {
        this.normalize();
        this.x *= length;
        this.y *= length;
        this.z *= length;
        return this;
    }

    public void normalize() {
        float _float = this.getLength();
        if (_float == 0.0F) {
            this.x = 0.0F;
            this.y = 0.0F;
            this.z = 0.0F;
        } else {
            this.x /= _float;
            this.y /= _float;
            this.z /= _float;
        }

        _float = this.getLength();
    }

    public Vector3 set(Vector3 other) {
        this.x = other.x;
        this.y = other.y;
        this.z = other.z;
        return this;
    }

    public Vector3 set(float _x, float _y, float _z) {
        this.x = _x;
        this.y = _y;
        this.z = _z;
        return this;
    }

    public Vector3 setLengthAndDirection(float direction, float length) {
        this.x = (float)(Math.cos((double)direction) * (double)length);
        this.y = (float)(Math.sin((double)direction) * (double)length);
        return this;
    }

    public Dimension toAwtDimension() {
        return new Dimension((int)this.x, (int)this.y);
    }

    public Point toAwtPoint() {
        return new Point((int)this.x, (int)this.y);
    }

    public String toString() {
        return String.format("Vector2 (X: %f, Y: %f) (L: %f, D:%f)", this.x, this.y, this.getLength(), this.getDirection());
    }

    public Vector3 sub(Vector3 val, Vector3 out) {
        return sub(this, val, out);
    }

    public static Vector3 sub(Vector3 a, Vector3 b, Vector3 out) {
        out.set(a.x - b.x, a.y - b.y, a.z - b.z);
        return out;
    }
}
